package com.traveldream.entities;

import java.io.Serializable;

import javax.persistence.*;


/**
 * The persistent class for the default_packet database table.
 * 
 */
@Entity
@Table(name="default_packet")
@NamedQueries({
	@NamedQuery(name="DefaultPacket.findAll", query="SELECT d FROM DefaultPacket d"),
	@NamedQuery(name="DefaultPacket.findBetweenDatesByPlace",query="SELECT p FROM DefaultPacket p WHERE  p.packet.startingDate > :start AND p.packet.endingDate < :end AND p.packet.place.name LIKE :placeNamee")
	
})
public class DefaultPacket implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name="packet_id",insertable=false,updatable=false)
	private int packetId;

	private int discount;

	//bi-directional one-to-one association to Packet
	@OneToOne
	private Packet packet;

	//bi-directional many-to-one association to User
	@ManyToOne
	@JoinColumn(name="employee_email")
	private User user;

	public DefaultPacket() {
	}

	public int getPacketId() {
		return this.packetId;
	}

	public void setPacketId(int packetId) {
		this.packetId = packetId;
	}

	public int getDiscount() {
		return this.discount;
	}

	public void setDiscount(int discount) {
		this.discount = discount;
	}

	public Packet getPacket() {
		return this.packet;
	}

	public void setPacket(Packet packet) {
		this.packet = packet;
	}

	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	
	public float getPrice()
	{
		return this.getPacket().getPrice();
	}
	public float getDiscountedPrice()
	{
		return (float)this.getPacket().getPrice()*(1-(float)this.getDiscount()/100);
	}
	
	@Override
	public boolean equals(Object obj) {
		DefaultPacket dp=(DefaultPacket) obj;
	    if(this.packet.equals(dp.packet)) {
	        return true;
	    }else {
	        return false;
	    }
	}
}